package com.aiit.carinsurance2.controller;

import com.aiit.carinsurance2.pojo.Car;
import com.aiit.carinsurance2.pojo.User;
import com.aiit.carinsurance2.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class CarController {

    @Autowired
    private CarService carService;


    @GetMapping("/car")
    public String getcar(){
        return "carinfo";
    }

    @PostMapping("/car")
    public String postcar(Car car ,HttpSession session){
        Object obj=session.getAttribute("user");

        User user =(User) obj;
        System.out.println(user);
        int id=((User) obj).getUid();
        car.setUid(id);
        int rlt=carService.addcarinfo(car);
        return "styles";
    }
}
